<link href="../addons/jy_newshopfee/custom/templates/mobile/style.css?v=201705251730" rel="stylesheet">
<style>
    .btn.btn-default-o{
        border-radius: 1rem;
        line-height: 1.1rem;
        height: 1.2rem;
        padding: 0 1rem;
        font-size: .6rem;
    }
    .towline{
        color: #000;
        font-size: 0.7rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        white-space: normal;
    }
    .fui-list-inner .text{
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;
        font-size: .7rem;
        color: #000;
    }
    .goods-selected .fui-list-inner{
        height: 4rem;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        -webkit-flex-direction: column;
        justify-content: space-between;
        -webkit-justify-content: space-between;
    }
</style>
<div ng-if="pagedata.selectgoods!=1" class="fui-page fui-page-current ">
	<div class="fui-header">
        <div class="fui-header-left">
            <a class="back" ng-click="goback();"></a>
        </div>
        <div class="title">自选商品</div>
    </div>
	<div class='fui-content'>
		<div class='fui-cell-group'>
			<div class='fui-cell'>
				<div class='fui-cell-info'>
					<div class="title">开启自选</div>
					<div class="subtitle">开启自选后，您的小店里只显示您选择的产品</div>
				</div>
				<div class='fui-cell-remark noremark'>
					<input ng-click="toogle(pagedata.myshop,'selectgoods',[0,1])" type="checkbox" class="fui-switch fui-switch-success fui-switch-small" ng-checked="pagedata.myshop.selectgoods==1" />
				</div>
			</div>
		</div>
		
		<div id="divselect" class="fui-cell-group" ng-if="pagedata.myshop.selectgoods">
		    <div class='fui-cell'>
				<div class='fui-cell-info'>
					<div class="title">开启分类</div>
					<div class="subtitle">如果您选择的商品较多，建议您开启与总店同步分类</div>
				</div>
				<div class='fui-cell-remark noremark'>
					<input ng-click="toogle(pagedata.myshop,'selectcategory',[0,1])" type="checkbox" class="fui-switch fui-switch-success fui-switch-small" ng-checked="pagedata.myshop.selectcategory==1" />
				</div>
			</div>
			  <div class='fui-cell'>
				<div class='fui-cell-info'>选择商品</div>
				<div class='fui-cell-remark noremark'><a class="text-warning" ng-click="pagedata.selectgoods=1"><i class="icon icon-add" style="font-size: .6rem"></i>添加商品</a></div>
			</div>
			<div id='goods-container' class='fui-list-group goods-selected-group' style="margin-top: 0">
				<div ng-repeat="g in pagedata.mygoods" class="fui-list goods-selected">
					<div class='fui-list-media'>
							<img ng-src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}" class='round' style="width: 4rem;height:4rem" />
					</div>
					<div class='fui-list-inner'>
							<div class='towline'>{{g.title}}</div>
							<div class='text'><span class="price">￥{{g.price}}</span><input type="checkbox" value="{{g.id}}" ng-checked="pagedata.goodsids.indexOf(';'+g.id+';')>=0" ng-click="pagedata.goselect(g.id,'goodsids')" class="fui-switch fui-switch-warning fui-switch-small"/></div>
						</div>
				</div>
			</div>
		</div>
		
		<div class='btn btn-warning block btn-submit mtop' ng-click="post(pagedata.myshop,'post')">保存设置</div>
	</div>
	 
</div>
<div ng-if="pagedata.selectgoods==1" class="fui-page fui-page page-commission-selectgoods" id="myshop-select-goods">
    <div class="fui-header">
        <div class="fui-header-left">
            <a class="back"></a>
        </div>
        <div class="title">选择商品</div>
		<div class="fui-header-right" ng-click="pagedata.selectgoods=0">完成</div>
    </div>
    <div class="fui-content navbar">
	<div class="fui-fullHigh-group" >
      
        <div class="fui-fullHigh-item menu" id="tab">
            <nav ng-class="{'on':pagedata.ctype =='all'}" ng-click="pagedata.getlist('all',0)">全部商品</nav>
			<nav ng-class="{'on':pagedata.ctype =='isnew'}" ng-click="pagedata.getlist('isnew',0)">新上宝贝</nav>
			<nav ng-class="{'on':pagedata.ctype =='isrecommand'}" ng-click="pagedata.getlist('isrecommand',0)">推荐宝贝</nav>
			<div ng-repeat="c1 in pagedata.category">
				<nav ng-class="{'on':pagedata.ctype ==c1.id}" ng-click="pagedata.getlist('',c1.id)" ng-show="!c1.enabled && pagedata.shopset.category.level !='-1'">{{c1.title}}</nav>
				<div ng-repeat="c2 in pagedata.category.childs[c1.id]">
					<nav ng-class="{'on':pagedata.ctype ==c2.id}" ng-click="pagedata.getlist('',c2.id)" ng-show="!c2.enabled && pagedata.shopset.category.level>=2">{{c2.title}}</nav>
					<nav ng-repeat="c3 in pagedata.category.childs[c2.id]" ng-class="{'on':pagedata.ctype ==c3.id}" ng-click="pagedata.getlist('',c3.id)" ng-show="!c3.enabled && pagedata.shopset.category.level>=3">{{c3.title}}</nav>
				</div>
			</div>
        </div>
        <div class="fui-fullHigh-item container">
              <div class="searchbar" style='margin:0;padding:0'>
                    <div class="search-input">
                        <i class="icon icon-search" ng-click="access(pagedata.op,made_query(pagedata.params))"></i>
                        <input type="search" id='keywords' ng-model="pagedata.params.keyword" placeholder="输入关键字..." style="border: 1px solid #f7f7f7;">
                    </div>
              </div>
				<p ng-if="pagedata.list.length<1" class="text-center text-cancel empty" style="margin-top:2rem;color:#999">暂时没有任何商品</p>
				<div class="fui-list-group goods-list-group" style="margin-top:0;">
					<div ng-repeat="g in pagedata.list" class="fui-list goods-item">
							<div class="fui-list-media">
								<img ng-src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}" class='round'/>
							</div>
							<div class='fui-list-inner'>
								<div class='subtitle'>{{g.title}}</div>
								<div class='text'><span class='text-danger'>￥{{g.price}}</span>
								<input type="checkbox" value="{{g.id}}" ng-checked="pagedata.goodsids.indexOf(';'+g.id+';')>=0" ng-click="pagedata.goselect(g.id,'goodsids')" class="fui-switch fui-switch-warning fui-switch-small"/></div>
							</div>
					</div>
				</div>
				<div ng-if="loading" class='infinite-loading'><span class='fui-preloader'></span><span class='text'> 正在加载...</span></div>
	   
        </div> 
    </div>
</div>
</div>
<div ng-include="sys_html('_footer')"></div>
<script>
scope.loading = true;  //状态标记
scope.isnodata = false;
scope.pagedata.list =[];
scope.pagedata.ctype ='all'
//滚动加载
scope.pagedata.params.keyword = ''
var page = 1;
scope.pagedata.getlist=function(order,cid){
		if(order){
			page = 1;
			scope.pagedata.list =[];
			scope.pagedata.ctype =order
		}else if(cid){
			page = 1;
			scope.pagedata.list =[];
			scope.pagedata.ctype =cid
		}
		scope.get('jy_newshopfee/selectgoods/getlist/page='+page+'&keyword='+scope.pagedata.params.keyword+'&order='+order+'&cid='+cid,
				function(data){	
					if(data.error !=1){
								for (var i=0;i<data.list.length;i++){
									scope.pagedata.list.push(data.list[i]);
								}
								if(page >1){
									$("#goodslist").animate({scrollTop:0},300);
								}
								if(data.list.length<1){
									scope.isnodata=true;
								}
								page++;
								scope.loading = false;
							}else{
								console.log('error!');
							};
			});
}
scope.pagedata.getlist();
window.addEventListener('scroll', function () {
	//alert('准备加载第二页');console.log('scope.isnodata');console.log(scope.loading);
	 var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
	// console.log(scrollTop);
    if(!scope.isnodata && !scope.loading &&  (scrollTop + window.innerHeight) >= document.documentElement.scrollHeight){
        scope.loading = true;  //状态标记
		scope.pagedata.getlist();
     }
})
scope.pagedata.goselect=function(value,field){
	var goodsids = scope.pagedata.goodsids;
		if(goodsids==undefined || goodsids==''){
			goodsids=';';
		}
		if(goodsids.indexOf(';'+value+';')<0){
			goodsids=goodsids+value+';';
		}else{
			goodsids=goodsids.replace(';'+value+';',';');
			if(goodsids==';'){
				goodsids='';
			}
		}
	scope.pagedata.goodsids = goodsids
	var params={
		data:{'id':value,'goodsids':goodsids},
		op:'selectgoods',
		callback:function(res){
			scope.pagedata.mygoods=res.mygoods
			scope.$evalAsync();
		}
	};
	scope.post_json(params);
}
</script>